<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HardwareList</title>
<link type="text/css" rel="stylesheet" href="css/gobal.css" />
<link type="text/css" rel="stylesheet" href="css/list.css" />
<script src="js/jquery1.7.2.js" type="text/javascript" ></script>
</head>
<body>
<div id="container">
	<div id="header">
    	<div class="soh1"><img src="css/images/header.gif"></div>
        <div class="soh2">
        	<div class="ssoh21"><p>硬件列表</p></div>
        	<div class="ssoh22">
        		<p>当前用户：${user==null?"游客":user}→<a href="/JspCart/userServlet?opt=exit">退出</a>→<a href="index.jsp">返回主页</a></p>
        	</div> 
    	</div>
    </div>

    <div id="main">
    	<div class="table">
	            <div class="trh">
                	<div class="tdh">编号</div><div class="tdh">分类</div><div class="tdh">名称</div><div class="tdh">价格</div><div class="tdh">库存</div>
                    <div class="tdh">厂商</div><div class="tdh">购买数量</div><div class="tdh">放入购物车</div><div class="tdh">结账</div>
                </div>
    		<c:forEach items="${hardwareList }" var="hardware">
				<div class="tr">
                	<div class="td">${hardware.id }</div><div class="td">${hardware.sort }</div><div class="td">${hardware.name }</div>
                    <div class="td">${hardware.price }</div><div class="td">${hardware.inventory }</div><div class="td">${hardware.brand }</div>
					<div class="tdform">
					<form action ="/JspCart/cartServlet?opt=add&sort=${sort}" method="post">
						<div class="td">
                    		<input type="hidden" name="id" value="${hardware.id}" />
                    		<input type="text" style="width:40px" name="num" value="1"/></div>
                    	<div class="td">
                    		<input type="submit" style="background-image:url(css/images/cart.gif);height:100%;width:80px;" value="" title="put into your cart"/>
                    	</div>
                    </form>
                    </div>
                    <div class="td"><a href="/JspCart/cartServlet?opt=show"><img src="css/images/go.gif" style="height:100%;width:100%;" title="Go"/></a></div>
                </div>
    		</c:forEach>
            <div class="tr">
            	<div class="tdf1">
            		${pageNum }/${pageCount }|
            		<a href="/JspCart/hardwareServlet?opt=sort&sort=${sort }&pageNum=1">首页|</a>
            		<a href="/JspCart/hardwareServlet?opt=sort&sort=${sort }&pageNum=${pageNum-1}">上一页|</a>
            		<a href="/JspCart/hardwareServlet?opt=sort&sort=${sort }&pageNum=${pageNum+1}">下一页|</a>
            		<a href="/JspCart/hardwareServlet?opt=sort&sort=${sort }&pageNum=${pageCount}">最后一页</a>
            		</div>
            	<div class="tdf2">
                    <form id="form" action="/JspCart/hardwareServlet?opt=sort&sort=${sort }" method="post">
                        <div class="sotf21">
                            <select id="page" style="width:70px" name="pageNum">
                                <option value="0">请选择</option>
                            </select>页
                        </div>
                        <div class="sotf22"><input type="submit" style="background-image:url(css/images/go.gif);height:100%;width:100%;" value="" title="Go" ></div>
                    </form>
                </div>
            </div>
        </div>
        <div class="table1">
       		<c:forEach items="${hardwareSort }" var="hardware">
    			<a href="/JspCart/hardwareServlet?opt=sort&sort=${hardware }">${hardware }</a><br>
    		</c:forEach>
        </div>
    </div>
<jsp:include page="/footer.jsp"/>
</div>
<script type="text/javascript">
$(function(){
	createOption();
	$("#form").submit(function(){
		return checkOption();
	});
});
/*只是玩玩 实际不可能用来分页 (页数过多就over)*/
function createOption(){
	var pageCount = ${pageCount } ;
	for(var i=1;i<=pageCount;i++){
		$("#page").append("<option value="+i+">"+i+"</option>");		
	};
};
function checkOption(){
	var value = $("#page").val();
	if (value == 0) {
		return false;
	} else {
		return true;
	};
};
</script>
</body>
</html>